import {request} from '../../network/index'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		hotTags:[],
		redact:false,
		A:[],
		B:[],
		C:[],
		D:[],
		E:[]
	},
	redact(){
		this.setData({
			redact:!this.data.redact
		})
	},
	sub(event){
		let item = event.currentTarget.dataset.item
		let index = event.currentTarget.dataset.index
		this.data.hotTags.splice(index,1)
		if(this.data.redact){
			if(item.category === 0){
				let itemData = this.data.A.find(i=>i.name == item.name)
				
				itemData.activity = false
				this.setData({
					hotTags:this.data.hotTags,
					A:this.data.A
				})
			}else if(item.category === 1){
				let itemData = this.data.B.find(i=>i.name == item.name)
				itemData.activity = false
				this.setData({
					hotTags:this.data.hotTags,
					B:this.data.B
				})
			}else if(item.category === 2){
				let itemData = this.data.C.find(i=>i.name == item.name)
				itemData.activity = false
				this.setData({
					hotTags:this.data.hotTags,
					C:this.data.C
				})
			}else if(item.category === 3){
				let itemData = this.data.D.find(i=>i.name == item.name)
				itemData.activity = false
				this.setData({
					hotTags:this.data.hotTags,
					D:this.data.D
				})
			}else{
				let itemData = this.data.E.find(i=>i.name == item.name)
				itemData.activity = false
				this.setData({
					hotTags:this.data.hotTags,
					E:this.data.E
				})
			}
		
		}else{
			wx.navigateTo({
				url: `/pages/tagMusicDetail/tagMusicDetail?name=${item.name}`,
			})
		}
	},
	add(event){
		let name = event.currentTarget.dataset.item
		let item = this.data.A.find(item=>item.name == name.name)
		if(this.data.redact){
			this.data.hotTags.push(name)
			item.activity = true
			this.setData({
				hotTags:this.data.hotTags,
				A:this.data.A
			})
		}else{
			wx.navigateTo({
				url: `/pages/tagMusicDetail/tagMusicDetail?name=${name.name}`,
			})
		}

	},
	add1(event){
		let name = event.currentTarget.dataset.item
		let item1 = this.data.B.find(item=>item.name == name.name)
		if(this.data.redact){
			this.data.hotTags.push(name)
			item1.activity = true
			this.setData({
				hotTags:this.data.hotTags,
				B:this.data.B
			})
		}else{
			wx.navigateTo({
				url: `/pages/tagMusicDetail/tagMusicDetail?name=${name.name}`,
			})
		}
	},
	add2(event){
		let name = event.currentTarget.dataset.item
		let item2 = this.data.C.find(item=>item.name == name.name)
		if(this.data.redact){
			this.data.hotTags.push(name)
			item2.activity = true
			this.setData({
				hotTags:this.data.hotTags,
				C:this.data.C
			})
		}else{
			wx.navigateTo({
				url: `/pages/tagMusicDetail/tagMusicDetail?name=${name.name}`,
			})
		}
	},
	add3(event){
		let name = event.currentTarget.dataset.item
		let item3 = this.data.D.find(item=>item.name == name.name)
		if(this.data.redact){
			this.data.hotTags.push(name)
			item3.activity = true
			this.setData({
				hotTags:this.data.hotTags,
				D:this.data.D
			})
		}else{
			wx.navigateTo({
				url: `/pages/tagMusicDetail/tagMusicDetail?name=${name.name}`,
			})
		}
	},
	add4(event){
		let name = event.currentTarget.dataset.item
		let item4 = this.data.E.find(item=>item.name == name.name)
		if(this.data.redact){
			this.data.hotTags.push(name)
			item4.activity = true
			this.setData({
				hotTags:this.data.hotTags,
				E:this.data.E
			})
		}else{
			wx.navigateTo({
				url: `/pages/tagMusicDetail/tagMusicDetail?name=${name.name}`,
			})
		}
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad:async function (options) {
		let hotTags = await request('/playlist/hot')
		let tags = await request('/playlist/catlist')

		let A = tags.data.sub.filter(item=>item.category === 0)
		let B = tags.data.sub.filter(item=>item.category === 1)
		let C = tags.data.sub.filter(item=>item.category === 2)
		let D = tags.data.sub.filter(item=>item.category === 3)
		let E = tags.data.sub.filter(item=>item.category === 4)

		this.setData({
			hotTags:hotTags.data.tags,
			A,
			B,
			C,
			D,
			E
		})
		console.log(this.data.hotTags);

		
		let tags1 = wx.getStorageSync('tags')

		if(tags1){
			this.setData({
				hotTags:tags1
			})
		}
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
	
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {
		
	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {
		wx.setStorageSync('tags',this.data.hotTags)
	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})